<?php
/**
 * 将本地所有文件移到images文件夹里
 */
include_once('../lib/config.php');
include_once('../lib/Db.class.php');
include_once('../lib/Model.class.php');
include_once('../lib/Upyun.class.php');
include_once('../lib/function.php');

$redis = new Redis();
$redis->connect(REDIS_IP, "6379");  //php客户端设置的ip及端口
if(!$redis) die('redis connect fail');
$redis->auth(REDIS_PASS);

$localDir = LIUDOUMI_DL_ROOT . '/images/';
$path = LIUDOUMI_IMAGES_PATH;

while (true) {
    $stop = $redis->get('LNPAN_QUEUE_STOP');
    if($stop) {
        die('stop');
    }

    $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); 
    foreach ($objects as $name => $object) { 
        if($object->isFile()){
            echo"$name\n";
            rename($name, $localDir . $object->getFilename());
            $redis->rPush('LIUDOUMI_IMAGES_PATH', $name);
        }
    }

}